package liujinliang.natappvip.cc.dispatcheventapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {

    // initialize a button
    private Button aButton;
    private Button anotherBtn;

    // initialize a layout
    private MyLinearLayout aLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Set up the button
        aButton = (Button) findViewById(R.id.btn);
        anotherBtn = (Button) findViewById(R.id.another_btn);

        // Set up the layout
        aLayout = (MyLinearLayout) findViewById(R.id.layout);

        // return false in onTouch()
//        aButton.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                Log.i("onTouch()", "action:" + event.getAction());
//                return true;
//            }
//        });
        aButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("Gene", "OnClick()——aButton clicked!");
            }
        });
        anotherBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("Gene", "OnClick()——anotherButton clicked!");
            }
        });
        aLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.i("Gene", "OnTouch()——aLayout clicked!");
                return false;
            }
        });


    }


}
